package de.justphil.tcg.tcgserver.rest.resources;

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.slf4j.Logger;

import de.justphil.tcg.tcgserver.commons.config.RestConfig;
import de.justphil.tcg.tcgserver.commons.exceptions.TCGException;
import de.justphil.tcg.tcgserver.rest.db.image.ImagesDirectory;
import de.justphil.tcg.tcgserver.rest.resources.base.AbstractResource;
import static de.justphil.tcg.tcgserver.commons.logging.TCGLogging.*;

@Path("/property")
public class PropertyResource extends AbstractResource {
	
	private static final Logger log = restLogger(PropertyResource.class);
	
	//private DataManager dataManager;
	
	public PropertyResource() {
		//dataManager = Application.getDataManager();
	}
	
	
	
	
	@GET
    @Path("/{propertyId: [0-9]+}/image")
    public Response getPropertyImage( 	@PathParam("propertyId") long propertyId,
    									@HeaderParam(RestConfig.REQ_HEADER_ACCEPT_LANGUAGE) String locale,
    									@HeaderParam(RestConfig.REQ_HEADER_AUTHORIZATION) String authHeader) {
		
		/*User user = */
		//aaa(dataManager, locale, authHeader);
		
		log.debug("getPropertyImage() propertyId => {}", propertyId);
		
    	try {
    		byte[] bytes = new ImagesDirectory().getPropertyImageFile(propertyId);
    		
    		return ok(bytes, "image/png");
    	}
    	catch (TCGException e) {
    		return err(e.getMessage(), (Status) e.getExtra(), locale, MediaType.APPLICATION_JSON_TYPE);
    	}
    }

}
